#include <iostream>
#include <vector>
#include <string>
#include <deque>
#include <map>
using namespace std;

int MoreThanHalfNum_Solution(vector<int> &numbers) {
    int candidate = numbers[0];
    int count = 1;
    for (int i = 1; i < numbers.size(); i++) {
        if (numbers[i] == candidate) {
            count++;
        } else {
            count--;
        }
        if (count == 0) {
            candidate = numbers[i + 1];
            count++;
        }
    }
    return candidate;
}

void Test1() {
    vector<int> numbers = {1, 2, 3, 2, 2};
    int result = MoreThanHalfNum_Solution(numbers);
    cout << "The number that appears more than half of the time is: " << result << endl;
}

void Test2() {
    string str;
    map<string, int> result;
    deque<string> deq;
    while (getline(cin, str)) {
        str = str.substr(str.find_last_of('\\') + 1);
        int pos = str.find_last_of(' ');
        if ( pos > 16) {
            str = str.substr(pos - 16);
        }

        if (result.find(str) == result.end()) deq.push_back(str);
        ++result[str];
        if (deq.size() > 8) deq.pop_front();
    }
    for (auto x : deq) {
        cout << x << " " << result[x] << endl;
    }
}

int main() {
    Test2();
    return 0;
}
